x86/vpmu: Fix race-condition in vpmu_load
authorTamas K Lengyel <tamas.lengyel@intel.com>
Tue, 11 Oct 2022 13:01:48 +0000 (15:01 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 11 Oct 2022 13:01:48 +0000 (15:01 +0200)
commit1bce7fb1f702da4f7a749c6f1457ecb20bf74fca
treefabd5df5503ed3a4e9e7e1c2fb65e2832363fadf
parent3f4da85ca8816f6617529c80850eaddd80ea0f1f
x86/vpmu: Fix race-condition in vpmu_load

The vPMU code-bases attempts to perform an optimization on saving/reloading the
PMU context by keeping track of what vCPU ran on each pCPU. When a pCPU is
getting scheduled, checks if the previous vCPU isn't the current one. If so,
attempts a call to vpmu_save_force. Unfortunately if the previous vCPU is
already getting scheduled to run on another pCPU its state will be already
runnable, which results in an ASSERT failure.

Fix this by always performing a pmu context save in vpmu_save when called from
vpmu_switch_from, and do a vpmu_load when called from vpmu_switch_to.

While this presents a minimal overhead in case the same vCPU is getting
rescheduled on the same pCPU, the ASSERT failure is avoided and the code is a
lot easier to reason about.

Signed-off-by: Tamas K Lengyel <tamas.lengyel@intel.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
master commit: defa4e51d20a143bdd4395a075bf0933bb38a9a4
master date: 2022-09-30 09:53:49 +0200
xen/arch/x86/cpu/vpmu.c